<template>
  <el-drawer v-model="drawer" title="I am the title" :with-header="false">

    <h2>反馈详情</h2>
    <p>{{ souid2.feedback }}</p>
    <p style="text-align: right;
    font-size: 0.8em;">{{ souid2.name }}</p>
        <p style="text-align: right;
    font-size: 0.8em;">联系电话：{{ souid2.phone}}</p>
    <p style="text-align: right;
    font-size: 0.8em;">联系邮箱：{{ souid.passenger.email}}</p>
    <p style="text-align: right;
    font-size: 0.8em;">{{ souid2.timestamp }}</p>
    <div class="flex-container">

      <el-descriptions title="反馈行程信息" :column="2" border>
        <el-descriptions-item label="路径" label-align="center" align="center">
          <el-tag size="small">{{ souid.passengerTrip.route }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="出发地点" label-align="center" align="center" label-class-name="my-label"
          class-name="my-content" width="150px">{{ souid.passengerTrip.startLocationName }}-{{
            souid.passengerTrip.startLocationLongitude }}</el-descriptions-item>
        <el-descriptions-item label="价格" label-align="center" align="center">{{ souid.passengerTrip.price
        }}</el-descriptions-item>
        <el-descriptions-item label="行程状态" label-align="center" align="center">{{ souid.passengerTrip.status
        }}</el-descriptions-item>

      </el-descriptions>
      <el-descriptions title="反馈车辆信息" :column="3" border>
        <el-descriptions-item label="司机名" label-align="center" align="center" label-class-name="my-label"
          class-name="my-content" width="100px">{{ souid.vehicleTrip.name }}</el-descriptions-item>
        <el-descriptions-item label="电话" label-align="center" align="center">{{ souid.vehicleTrip.phone
        }}</el-descriptions-item>
        <el-descriptions-item label="车牌号" label-align="center" align="center">{{ souid.vehicleTrip.vehicleLicense
        }}</el-descriptions-item>
        <el-descriptions-item label="车载状况" label-align="center" align="center">{{ souid.vehicleTrip.numPassengers }}/{{
          souid.vehicleTrip.maxSeatCapacity }}</el-descriptions-item>
        <el-descriptions-item label="出发时间" label-align="center" align="center">{{ souid.vehicleTrip.startDate }}{{
          souid.vehicleTrip.startTime }}</el-descriptions-item>
      </el-descriptions>
    </div>
  </el-drawer>
  <div class="table-container">
    <h1>反馈管理</h1>
    <el-table class="my-table" :data="currentPageData" :style="{ width: '100%', minHeight: GD001 + 'px' }">
      <el-table-column label="反馈时间" prop="timestamp" width="220px"  />
      <el-table-column label="反馈行程编号" prop="vehicleTripId" width="180px"></el-table-column>
      <el-table-column label="反馈用户昵称" prop="name" width="180px"></el-table-column>
      <el-table-column label="反馈用户电话" prop="phone" width="180px"></el-table-column>
      <el-table-column label="反馈内容" prop="feedback"    show-overflow-tooltip="true" 
   width="300px" />
      <el-table-column align="right">
        <template #header>
          <el-input v-model="search" size="small" placeholder="请输入搜索内容"  style="height: 30px"/>
        </template>
        <template #default="scope">
          <el-button size="small"  type="primary" @click="drawer = true, handleEdit(scope.row)">查看详情</el-button>

        </template>
      </el-table-column>
    </el-table>

  </div>
  <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
    :page-sizes="[4, 6, 8]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
    :total="allData.length"/>
</template>
  
<script  setup>
import { computed, ref } from 'vue'
import request from '../utils/request'
import { CircleCloseFilled } from '@element-plus/icons-vue'

const visible = ref(false)

const search = ref('')
const tableData = ref([]) // 将tableData定义为一个ref

const souid = ref(
  {
    "passenger": {
      username: '',
      phone: '',
      email: '',
    },
    "passengerTrip": {
      route: '',
      startLocationName: '',
      startLocationLongitude: '',
      price: '',
      status: '',
    },
    "vehicleTrip": {
      name: '',
      vehicleLicense: '',
      numPassengers: '',
      maxSeatCapacity: '',
      startDate: '',
      username: '',
      phone: '',
      startTime: '',
    }
  })
const souid2 = ref({
  feedback: "",
  timestamp: "",
})
const handleEdit = (row) => {

  souid2.value = row

  request.get(`/manager/queryFeedBackById/${row.vehicleTripId}/${row.passengerId}/${row.passengerTripId}`)
    .then(result => {

      if (result.success) {
        souid.value = result.data // 请求成功后，将result.data赋值给allData
        const data1 = new Date(souid.value.vehicleTrip.startDate);
        const data2 = new Date(souid.value.vehicleTrip.startTime);
        souid.value.vehicleTrip.startDate = `${data1.getFullYear()}年${data1.getMonth() + 1}月${data1.getDate()}日`;
        souid.value.vehicleTrip.startTime = `${data2.getHours()}时${data2.getMinutes()}分${data2.getSeconds()}秒`;
      }
    })

}
const drawer = ref(false)
const handleDelete = (index, row) => {
  console.log(index, row)
}
const allData = ref([{

  
      "passenger": {
        "id": null,
        "username": "",
        "password": null,
        "email": null,
        "name": "",
        "phone": "",
        "registerTime": null,
        "isDeleted": null,
        "photo": null

      },
      "name": "",
      "id": null,
      "passengerId": null,
      "passengerTripId": null,
      "vehicleTripId": null,
      "feedback": null,
      "timestamp": null,
      "phone": "null",
      "isDeleted": null
    

}]) // 存储所有的数据
const currentPage = ref(1) // 当前页码
const pageSize = ref(6) // 每页的数据量

const currentPageData = computed(() => { // 计算当前页的数据
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return filteredData.value.slice(start, end)
})
const GD001 = ref(497)

const handleSizeChange = (val) => { // 处理每页数据量改变的事件

  pageSize.value = val
  GD001.value=val*75+47
  currentPage.value = 1 // 每次改变每页数据量时，都将页码重置为1
}

const handleCurrentChange = (val) => { // 处理页码改变的事件
  currentPage.value = val
}

request.get("/manager/queryFeedback").then(result => {
  if (result.success) {
    allData.value = result.data // 请求成功后，将result.data赋值给allData

    allData.value.forEach(item => {
      var date = new Date(item.timestamp);
      var formattedDate = date.getFullYear() + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日" + date.getHours() + "时" + date.getMinutes() + "分";
      item.timestamp = formattedDate;
      item.name=item.passenger.name
      item.phone=item.passenger.phone
    });
  }
})

// 添加一个计算属性来过滤数据
const filteredData = computed(() => {
  if (!search.value) {
    return allData.value;
  }
  return allData.value.filter((data) =>
    Object.values(data).some((value) =>
      String(value).toLowerCase().includes(search.value.toLowerCase())
    )
  );
});


</script>
<style>
.el-table .el-table__body tr {
  height: 75px; /* 你想要的行高 */
}

</style>
